<?php
namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Category extends Index
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function Cateindex($id)
    {
        //根据分类id加载子类id
        $gid = Db::name('category')->field('id,name')->where('path like "%,'.$id.',%"')->select();

//        遍历成字串形式 6,7,8,9,0(二级分类)
        $gidList = '';
        foreach ($gid as $k => $v) {
            $gidList .= $v['id'].',';
        }
        $gidList .=$id;
        $yshop = Db::name('yshop')->field('id')->where(["gid "=>$gidList])->select();

        //查找图片介绍
//        定义一个空数组
        $yshop_show = array();
        foreach($yshop as $v){
            $sid = $v['id'];

            $yshop_show[] = Db::name('yshop_show')->field('sid,comment,icon')->where(['face'=>1,'sid'=>$sid])->select();
        }
        $ids = $id;
        return view('index@category/index',[
            'category' => parent::category(),
            'cates' => $gid,
            'show'=>$yshop_show,
            'id' => $ids
        ]);
    }

    /**
     * 显示商铺首页.
     * @param  int  $id
     * @return \think\Response
     */
    public function create($id)
    {

        $yshop = Db::name('yshop')->where(['id'=>$id])->find();
//        商店轮播
        $yshop_banner = Db::name('yshop_banner')->field('icon')->where(['sid'=>$yshop['id'],'display'=>1])->select();
//        商店室内环境
        $yshop_show = Db::name('yshop_show')->where(['sid'=>$yshop['id'],'display'=>1])->select();
        $ids = $id;
//        菜单
        $sid = $id;
        return view('index@category/shop',[
            'ban' => $yshop_banner,
            'sh' => $yshop_show,
            'id' => $ids

        ]);
    }

    /**
     * @param $id
     * @return \think\response\View
     * 指定店铺id
     */
    public function menu($id)
    {
        $ids = $id;
        $yshop_menu = Db::name('yshop_menu')->where(['sid'=>$ids])->select();
        return view('index@category/menu',[
            'id' => $ids,
            'sm' =>$yshop_menu,
        ]);
    }
    /**
     * @param $id
     * @return \think\response\View
     * 菜单zmj
     */
    public function order($id){
        $ids = $id;
        $sid = Session::get('index.id');
        return view('index@category/order',[
            'id' => $ids,
            'sid' => $sid
        ]);
    }

}
